/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Filename      : mpu_outband_cmd_defs.h
 * Version       : Initial Draft
 * Creation time : 2023/08/26
 * Last Modified :
 * Description   : SMBUS protocol out-of-band command related structure
 */

#ifndef MPU_OUTBAND_SMBUS_CMD_DEFS_H
#define MPU_OUTBAND_SMBUS_CMD_DEFS_H

#include "mag_mpu_cmd_defs.h"

#define SMB_SINGLE_SLICE_LOG_LEN 48
#define MAX_PORT_LEN 8
#define SMB_HW_RESERVED_LEN (82 + 256)
#define SMB_SPU_RAS_LEN (12)
#define SMB_MAC_ADDR_INFO_LEN (48)
#define PORT_MAP_MAX_LEN 4

#define SMB_PORT_NUM 24
#define SFP_MAX_PORT_NUM 8 /* 光模块端口数 */


/* 带外管理公共的响应消息头 */
typedef struct {
    u16 errcode;
    u16 opcode;
    u32 total_length;
    u32 length;
} smb_respon_header_s;

typedef struct {
    u16 reserved;
    u16 opcode;
} smb_ctrl_header_s;

typedef struct {
    u32 total_cell_num;
    u32 free_cell_num;
    u32 pdm_glb_num;
    u32 cpi_octl_cell_num;
    u32 leak_cell_num;
    u32 fq_free_oeid_num;
} chip_cell_info_s;

typedef struct {
    u32 abort_bf_ipsurx_cnt;
    u32 sop_sop_err_cnt;
    u32 dmac_zero_cnt;
    u32 da_sa_equal_cnt;
    u32 arp_posi_ilgl_cnt;
    u32 ipv4_ver_ilgl_cnt;
    u32 ipv4_ihl_ilgl_cnt;
    u32 ipv4_sip_ilgl_cnt;
    u32 ipv4_dip_ilgl_cnt;
    u32 ipv6_ver_ilgl_cnt;
    u32 ipv6_sip_ilgl_cnt;
    u32 ipv6_dip_ilgl_cnt;
    u32 tcp_land_ilgl_cnt;
    u32 rocev1_dgid_ilgl_cnt;
    u32 rocev1_sgid_ilgl_cnt;
    u32 rocev1_ipver_ilgl_cnt;
    u32 rocev1_nxhdr_ilgl_cnt;
    u32 roce_dqp_ilgl_cnt;
    u32 eth_len_ilgl_cnt;
    u32 pkt_min_len_ilgl_cnt;
    u32 pkt_max_len_ilgl_cnt;
    u32 ipv4_cs_ilgl_cnt;
    u32 tcp_cs_ilgl_cnt;
    u32 udp_cs_ilgl_cnt;
    u32 igmp_cs_ilgl_cnt;
    u32 icmpv4_cs_ilgl_cnt;
    u32 icmpv6_cs_ilgl_cnt;
    u32 sctp_cs_ilgl_cnt;
    u32 fc_crc_ilgl_cnt;
    u32 rocev1_plen_ilgl_cnt;
    u32 ib_icrc_ilgl_cnt;
    u32 smac_ilgl_cnt;
    u32 ipv6_udp_cs_zero_cnt;
    u32 rocev2_ipv4_frag_ilgl_cnt;
    u32 rocev2_ipv4_udp_cs_ilgl_cnt;
    u32 rocev2_ipv6_udp_cs_ilgl_cnt;
    u32 to_up_pkt_ilgl_cnt;
    u32 to_bmc_only_pkt_ilgl_cnt;
} ipsurx_pkt_err_cnt_s;

/*
 * *巡检信息文件结构，总计198KB*
 * *smb_hw_info_s-----------8KB*
 * *up counter--------------6KB*
 * *ucode counter---------184KB*
 */

typedef struct {
    /* nic base info 16byte */
    u32 fw_ver;
    u16 pcie_cap;
    u16 port_num;
    u16 port_speed_mode;
    u16 work_mode;
    u16 sub_work_mode;
    u16 reserved0;

    /* port 管理信息 48bytes */
    u16 link_status[MAX_PORT_LEN];
    u16 port_mode[MAX_PORT_LEN];
    u16 speed[MAX_PORT_LEN];

    /* up status 184 */
    u32 memory_usage;                 /**< 4bytes */
    u32 usage_unit;                   /**< 4bytes 当前单位为1/10000 */
    chip_cell_info_s cpb_utilization; /**< chip cell info, 24bytes @see chip_cell_info_s */
    ipsurx_pkt_err_cnt_s ipsu_err;    /**< ipsurx pkt err cnt, 152bytes @see ipsurx_pkt_err_cnt_s */
} smb_global_info_s;

#pragma pack(1) /* 一字节对齐 */

typedef union {
    /* 保证结构体的每个成员的大小为32 */
    struct {
        u16 id;
        u8 type;
        u8 reserved;
        u16 cap_num;
        u16 opc_data[(SMB_SINGLE_SLICE_LOG_LEN - 6) / 2];
    } first_frame;
    struct {
        u16 opc_data[SMB_SINGLE_SLICE_LOG_LEN / 2];
    } other_frame;
} ability_data_u;
 typedef struct {
    smb_respon_header_s res_header;
    ability_data_u ability_data;
    u32 crc32;
} smb_ability_s;

typedef struct {
    smb_respon_header_s res_header;
    u8 health_status;
    u32 crc32;
} smb_device_health_s;

/* Define the common struct 32bytes data u16,example:errcode */
typedef struct {
    smb_respon_header_s res_header;
    u8 data[SMB_SINGLE_SLICE_LOG_LEN];
    u32 crc32;
} smb_com_res_s;

typedef struct {
    smb_respon_header_s res_header;
    s16 temp; /* 需要将实际温度扩大10倍发送给master */
    u32 crc32;
} smb_temperature_s;

/* 阈值 */
typedef struct {
    s32 max_temp; /**< 芯片核温阈值 */
    s32 min_temp; /**< 芯片核温阈值 */
} smb_temp_threshold_data_s;

/* 核温阈值 */
typedef struct {
    smb_ctrl_header_s header;
    u32 op_type; /**< 0：读阈值；1：写阈值 */
    smb_temp_threshold_data_s temp_threshold_data; /**< temperature threshold @see smb_temp_threshold_data_s */
    u32 crc32;
} smb_temp_threshold_s;

/* Define the struct read_log 48bytes log，lastword?rrespec */
typedef struct {
    smb_respon_header_s res_header;
    u8 log_data[SMB_SINGLE_SLICE_LOG_LEN]; /* master 读日志的长度能力小于该值需要按照master能力处理 */
    u32 crc32;
} smb_log_s;


/* 要求32byte对齐，总计8KB */
typedef struct {
    smb_global_info_s global_info;
    /* MIB影子统计信息,总计6592Bytes */
    struct mag_port_stats mag_shadow_stats[PORT_MAP_MAX_LEN];  /**< MIB影子统计信息,总计6592Bytes @see mag_port_stats */
    u32 reserved0[SMB_HW_RESERVED_LEN];
} smb_hw_info_s;

typedef struct {
    smb_respon_header_s res_header;
    s16 phy_temp_data[SMB_PORT_NUM];
    u32 crc32;
} smb_phy_temp_s;

typedef struct {
    smb_respon_header_s res_header;
    s16 sfp_temp_data[SMB_PORT_NUM];
    u32 crc32;
} smb_sfp_temp_s;

typedef struct {
    smb_respon_header_s res_header;
    u16 sfp_id_data[SFP_MAX_PORT_NUM];
    u32 rsvd0;
    u32 rsvd1;
    u32 crc32;
} smb_sfp_id_s;

typedef struct {
    smb_ctrl_header_s header;
    u32 op_type; /**< 0：读阈值；1：写阈值 */
    smb_temp_threshold_data_s sfp_threshold_data; /**< temperature threshold @see smb_temp_threshold_data_s */
    u32 crc32;
} smb_sfp_temp_threshold_s;

typedef struct {
    smb_respon_header_s res_header;
    u8 link_stat[SMB_PORT_NUM];
    u32 crc32;
} smb_link_stat_s;

typedef struct {
    u8 major;
    u8 minor;
    u8 revison; /* revison若不涉及则填0xff */
} firmware_ver_data_s;

typedef struct {
    smb_respon_header_s res_header;
    firmware_ver_data_s ver_data;
    u32 crc32;
} smb_firmware_ver_s;


typedef struct {
    smb_respon_header_s res_header;
    s16 spu_tsensor_temp;
    u32 crc32;
} smb_spu_temp_s;

typedef struct {
    smb_respon_header_s res_header;
    u8 pwrlimit_en; /**< 0:open 1:close */
    u32 crc32;
} smb_spu_pwrlimit_en_s;

typedef struct {
    smb_respon_header_s header;
    u8 num_item;
    u32 crc32;
} smb_spu_ras_num_s;

typedef struct {
    smb_respon_header_s header;
    u32 ras_info[SMB_SPU_RAS_LEN]; // 每4B为 imu_to_mcu_ras_info_s 结构
    u32 crc32;
} smb_spu_ras_s;

#pragma pack()

/* 获取MAC addr */
typedef struct {
    smb_respon_header_s res_header;
    u8 mac_addr[SMB_MAC_ADDR_INFO_LEN];
    u32 crc32;
} smb_mac_addr_s;

typedef struct {
    smb_respon_header_s res_header;
    u16 spu_freq;
    u8 spu_freq_status;
    u8 rsvd;
    u32 crc32;
} smb_spu_freq_resp_s;

/* Define the struct read_write_reg 5*4bytes */
typedef struct {
    u32 addr_h;
    u32 addr_l;
    u32 data_h;
    u32 data_l;
} smb_rw_reg_payload_s;

typedef struct {
    smb_ctrl_header_s header;
    smb_rw_reg_payload_s payload;
    u32 crc32;
} smb_read_write_reg_s;

typedef struct {
    smb_ctrl_header_s res_header;
    u16 func_id;
    u8 opcode;
    u8 outband_defvid_flag;
    u16 vlan_id;
    u16 rsvd;
    u32 crc32;
} smb_nic_func_vlan_cfg_s;

#endif